package com.mycity.services;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.mycity.bean.Report;
import com.mycity.dao.ReportDao;

public class ReportService {
	private ReportDao reportDao=new ReportDao();
	private ProfileService profileService = new ProfileService();

	public List<Report> numberReportsOfContent(int contentId, int contentType) throws Exception{
		List<Report> reportList;
		try {
			reportList = reportDao.getReports(contentId,contentType);
		} catch (Exception e) {
			return null;
		}
		return reportList;
	}


	public int reportOn(int contentType, int contentId, int reporterId, int reportedId) throws Exception{
		int reportId;
		boolean check;
		String today = new SimpleDateFormat("dd/MM/yyyy HH:mm").format(new Date());
		try{
			reportId=reportDao.reportContent(contentType, contentId, reporterId, reportedId, today);
			check=reportDao.reportControl(contentId, contentType);
			if(check){

				if(contentType==1){
					profileService.deletePost(contentId);
				}
				else{
					profileService.deleteComment(contentId);
				}
				reportDao.deleteFromReportTable(contentId, contentType);
			}
		} catch (Exception e) {
			return -1;
		}
		return reportId;
	}

}
